The >copy *.txt windows command at CMD prompt copies all text files but If you want to also copy each filename before copying each file.then how to do this, is explained in this post.
To copy all .txt files and also record each filename before copying its contents into a.txt, you can use a for loop in the Command Prompt (cmd.exe). Here's a command that does exactly that:
(for %f in (*.txt) do @echo === %f === & type "%f") > a.txt
Explanation:
- for %f in (*.txt) – loops through all .txt files in the current directory.
- @echo === %f === – writes the filename (surrounded by markers for clarity).
- type "%f" – writes the contents of the file.
- > redirects the entire output into a.txt.
Output Example (a.txt will look like this):
=== file1.txt ===
This is content of file1
=== file2.txt ===
This is content of file2
Note: If you are running this inside a batch file (.bat):
You must double the % signs:
(for %%f in (*.txt) do @echo === %%f === & type "%%f") > a.txt
No comments:
Post a Comment